﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace IndyMosaic.Models.Web
{
    public partial class NewsItem : Validatable
    {
        partial void OnCreated()
        {
            this.Title = string.Empty;
            this.Body = string.Empty;
            this.ExpirationDate = DateTime.MinValue;
        }
        partial void OnValidate(System.Data.Linq.ChangeAction action)
        {
            if (!IsValid)
            {
                throw new ApplicationException("Rule violations prevent saving");
            }
        }
        public override IEnumerable<RuleViolation> GetRuleViolations()
        {
            if (string.IsNullOrWhiteSpace(this.Body))
            {
                yield return new RuleViolation("Body is required", "Body");
            }
            if (string.IsNullOrWhiteSpace(this.Title))
            {
                yield return new RuleViolation("Title is required", "Title");
            }
            if (this.ExpirationDate == DateTime.MinValue)
            {
                yield return new RuleViolation("Expiraiton date must be set", "ExpirationDate");
            }
        }
    }
}
